/**
 * 对象转QueryString
 * @param obj
 */
export const objToQueryString = (obj: any, encode?: boolean) => {
  return Object.keys(obj)
    .map(i => `${i}=${encode ? encodeURIComponent(obj[i]) : obj[i]}`)
    .join("&");
};

/**
 * QueryString转Object
 * @param str
 */
export const queryStringToObj = (str: string) => {
  return str.split("&").reduce((obj, i) => {
    const [key, value] = i.split("=");
    obj[key] = decodeURIComponent(value);
    return obj;
  }, {} as any);
};
